package cn.tedu.wallet.controller;

import cn.tedu.base.response.JsonResult;
import cn.tedu.base.response.StatusCode;
import cn.tedu.wallet.pojo.param.ArticlePayRecordParam;
import cn.tedu.wallet.pojo.param.RecordParam;
import cn.tedu.wallet.pojo.po.UserTransactionRecordPO;
import cn.tedu.wallet.pojo.vo.UserTransactionRecordVO;
import cn.tedu.wallet.service.RecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wallet/record")
@Slf4j
@Api(tags = "消费记录模块")
public class RecordController {

    @Autowired
    private RecordService recordService;

    @PostMapping("/prepare")
    @ApiOperation("准备添加交易记录")
    public JsonResult prepareAddRecord(@RequestBody RecordParam param) {
        log.debug("控制器收到前端交易记录参数{},准备添加", param);
        String recordId = recordService.prepareRecord(param);
        return new JsonResult(StatusCode.OPERATION_SUCCESS, recordId);
    }

    @PostMapping("/add")
    @ApiOperation("添加交易记录")
    public JsonResult addRecord(@RequestBody RecordParam param) {
        log.debug("控制器收到前端交易记录参数{}", param);
        Integer data = recordService.addRecord(param);
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }

    @GetMapping("/select/confirm")
    @ApiOperation("验证文章购买记录")
    public JsonResult selectArticlePayRecord(ArticlePayRecordParam param) {
        log.debug("控制器收到前端查询数据{}", param);
        Integer confirm = recordService.SelectArticlePayRecord(param);
        return new JsonResult(StatusCode.OPERATION_SUCCESS, confirm);
    }

    @GetMapping("/select/{userId}")
    @ApiOperation("查询所有交易记录")
    public JsonResult selectUserPayRecord(@PathVariable Long userId) {
        log.debug("控制器收到前端用户id{}", userId);
        List<UserTransactionRecordVO> recordVOList = recordService.SelectUserPayRecord(userId);
        return new JsonResult(StatusCode.OPERATION_SUCCESS, recordVOList);
    }

    @GetMapping("/select/recordStatus/{recordId}")
    @ApiOperation("查询交易记录状态")
    public JsonResult selectRecordDetail(@PathVariable Long recordId) {
        log.debug("控制器收到前端交易记录id{}", recordId);
        Integer status = recordService.selectRecordStatus(recordId);
        return new JsonResult(StatusCode.OPERATION_SUCCESS, status);
    }
}
